/****************************************************************************************
**  File: Box.hpp
**  Author: Asteroth
**  Date: 22/02/2009
****************************************************************************************/

#ifndef __BOX_HPP__
#define __BOX_HPP__

template <class T>
class Boxx {
public:
	T X, Y, Z, W, H, D;

	Boxx():								X(0), Y(0), Z(0), W(0), H(0), D(0) {}
	Boxx(const Boxx<T> &box):			X(box.X), Y(box.Y), Z(box.Z), W(box.W), H(box.H), D(box.D) {}
	Boxx(T x, T y, T z, T w, T h, T d):	X(x), Y(y), Z(z), W(w), H(h), D(d) {}

	inline Boxx<T> &operator = ( const Boxx<T> &set ) {
		X = set.X;
		Y = set.Y;
		Z = set.Z;
		W = set.W;
		H = set.H;
		D = set.D;
		return *this;
	}

	// Results a cube containing both
	inline Boxx<T> &operator += ( const Boxx<T> &add ) {
		T x = eMin(X, add.X);
		T y = eMin(Y, add.Y);
		T z = eMin(Z, add.Z);
		W = eMax(X + W, add.X + add.W) - x;
		H = eMax(Y + H, add.Y + add.H) - y;
		D = eMax(Z + D, add.Z + add.D) - z;
		X = x;
		Y = y;
		Z = z;
		return *this;
	}

	// Results a cube containing both
	inline Boxx<T> operator + ( const Boxx<T> &add ) const {
		T x = eMin(X, add.X);
		T y = eMin(Y, add.Y);
		T z = eMin(Z, add.Z);
		return Boxx<T>(x, y, z, eMax(X + W, add.X + add.W) - x, eMax(Y + H, add.Y + add.H) - y, eMax(Z + D, add.Z + add.D) - z);
	}

	// Is inside: a[ b ]  ->  b inside a
	inline bool operator [] (const Vector3x<T> &vect) const {
		if (vect.X >= X && vect.Y >= Y && vect.Z >= Z && vect.X < X + W && vect.Y < Y + H && vect.Z < Z + D)
			return true;
		return false;
	}

	// Is inside: a[ b ]  ->  b inside a
	inline bool operator [] (const Boxx<T> &box) const {
		if (box.X >= X && box.Y >= Y && box.Z >= Z && box.X + box.W <= X + W && box.Y + box.H <= Y + H && box.Z + box.D <= Z + D)
			return true;
		return false;
	}
};

typedef Boxx<float> Box;

#endif
